package com.qcs.sleep.warn;

import com.qcs.sleep.OnWarnListener;

/**
 * Created by chshqiang on 13-10-17.
 * 看视频示警
 */
public class VideoWarnAdapter extends LauncherWarnAdapter {
    // com.zhadui.stream
    // com.mediatek.videoplayer
    private final int FIRST_SEE_VIDEO_DELAY = 180 * 60;

    private OnWarnListener mListener;

    private boolean isSeeVideo = false;

    private int nextWarnDelay = FIRST_SEE_VIDEO_DELAY;
    private int seeVideoTime = 0;

    @Override
    public void run() {
        if (isSeeVideo) {
            seeVideoTime++;

            if (seeVideoTime >= nextWarnDelay) {
                nextWarnDelay += nextWarnDelay / 6;

                mListener.onWarn(59, OnWarnListener.FLAG_ACTIVITY, null);
            }
        } else {
            if (0 >= seeVideoTime)
                return;

            seeVideoTime -= seeVideoTime / 10; // 有过上网行为，此时未上网，则削弱上网的总计时
        }
    }

    @Override
    public void onReceive(int flag, String action) {
        if (APP != flag)
            return;

        isSeeVideo = (action.contains("com.zhadui.stream") || action.contains("com.mediatek.videoplayer"));
    }

    @Override
    public void setOnWarnListener(OnWarnListener listener) {
        mListener = listener;
    }}
